﻿//////////////////////////////////////////////////////////////////////////////
//
//  Copyright © 1998-2024 Glodon Company Limited.  All rights reserved.
//
//  Use of this software is subject to the terms of the Glodon license
//  agreement provided at the time of installation or download, or which
//  otherwise accompanies this software in either electronic or hard copy form.  
//
//////////////////////////////////////////////////////////////////////////////

// Reviewed

#pragma once


#include "GcmpMathInterface.h"
#include "GbmpConstants.h"

namespace gcmp
{
    /// \brief  数学基础工具类
    ///
    /// 
    class GCMP_MATH_INTERFACE_EXPORT MathUtils
    {
    public:

        /// \brief   两个浮点数是否相等
        ///
        /// \param value1  数值1
        /// \param value2  数值2
        /// \param eps  误差
        /// \return   true: 是， false: 否
        static bool IsEqual(double value1, double value2, double tolerance = Constants::DOUBLE_EPS);

        /// \brief   判断浮点数是否等于0
        ///
        /// \param value  数值
        /// \param eps  误差
        /// \return   true: 是， false: 否
        static bool IsZero(double value, double tolerance = Constants::DOUBLE_EPS);

        /// \brief    判断value1是否大于value2
        ///
        /// \param value1  数值1
        /// \param value2  数值2
        /// \param tolerance  误差
        /// \return   true: 是， false: 否
        static bool IsGreaterThan(double value1, double value2, double tolerance = Constants::DOUBLE_EPS);

        /// \brief    判断value1是否大于等于value2
        ///
        /// \param value1  数值1
        /// \param value2  数值2
        /// \param tolerance  误差
        /// \return   true: 是， false: 否
        static bool IsGreaterThanOrEqual(double value1, double value2, double tolerance = Constants::DOUBLE_EPS);

        /// \brief   判断value1是否小于value2
        ///
        /// \param value1  数值1
        /// \param value2  数值2
        /// \param tolerance  误差
        /// \return  true: 是， false: 否
        static bool IsLessThan(double value1, double value2, double tolerance = Constants::DOUBLE_EPS);

        /// \brief   判断value1是否小于等于value2
        ///
        /// \param value1  数值1
        /// \param value2  数值2
        /// \param tolerance  误差
        /// \return  true: 是， false: 否
        static bool IsLessThanOrEqual(double value1, double value2, double tolerance = Constants::DOUBLE_EPS);

        /// \brief  数值取整
        ///
        /// \param value 数值
        /// \return  整数值
        static double Round(double value);
 
        /// \brief 判断某个值是否为无穷大
        ///
        /// \param value 某个值
        /// \return true: 是， false: 否
        static bool IsInfinite(double value);

        /// \brief 判断某个值是否为无效值
        ///
        /// \param value 某个值
        /// \return true: 是， false: 否
        static bool IsNan(double value);

        /// \brief 判断某个值是否为合理值(非无穷大、非无效值)
        ///
        /// \param value 某个值
        /// \return true: 是， false: 否
        static bool IsValid(double value);

        /// \brief  弧度值转换角度值
        ///
        /// \param radians 弧度值
        /// \return  角度值
        static double RadiansToAngle(double radians);

        /// \brief  角度值转换弧度值
        ///
        /// \param angle  角度值
        /// \return  弧度值
        static double AngleToRadians(double angle);

        /// \brief   限制数值在min和max之间
        ///
        /// \param min   区间最小值
        /// \param max   区间最大值
        /// \param value 数值
        /// \return 
        static void Clamp(const double &min, const double &max, double &value);
    };
}


